package com.project.personalfundmanager.client.common;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.project.personalfundmanager.client.taxitems.IncomeItem;
import com.project.personalfundmanager.client.taxitems.ParentItem;
import com.project.personalfundmanager.client.taxitems.Section10Item;
import com.project.personalfundmanager.client.taxitems.Section24Item;
import com.project.personalfundmanager.client.taxitems.Section80CItem;
import com.project.personalfundmanager.client.taxitems.SectionOthersItem;
import com.project.personalfundmanager.shared.models.TaxInfoGroupModel;

public class ModelHelper
{
	public static Integer getNullSafeInt( Object value )
	{
		return value == null ? 0 : ( ( Number ) value ).intValue();
	}

	public static List<BaseModel> getAllInputModels( TaxInfoGroupModel taxGroupModel )
	{
		List<BaseModel> models = new ArrayList<BaseModel>();
		models.add( taxGroupModel.getTaxableIncome() );
		models.add( taxGroupModel.getSection10Model() );
		models.add( taxGroupModel.getSection24Model() );
		models.add( taxGroupModel.getSection80CModel() );
		models.add( taxGroupModel.getSectionOthersModel() );
		return models;
	}

	@SuppressWarnings("unchecked")
	public static List<ParentItem> getModelWrappers( TaxInfoGroupModel taxGroupModel )
	{
		List<ParentItem> items = new ArrayList<ParentItem>();
		items.add( new IncomeItem( taxGroupModel.getTaxableIncome() ) );
		items.add( new Section10Item( taxGroupModel.getSection10Model(), taxGroupModel.getTaxableIncome() ) );
		items.add( new Section24Item( taxGroupModel.getSection24Model() ) );
		items.add( new Section80CItem( taxGroupModel.getSection80CModel() ) );
		items.add( new SectionOthersItem( taxGroupModel.getSectionOthersModel() ) );
		return items;
	}
}
